<?php

/* 微公众平台接口管理控制器 */

class My_wxconfigApp extends BackendApp {
    function index() {
        $model_setting = &af('settings');
        $setting = $model_setting->getAll(); //载入系统设置数据
        if (!IS_POST) {
            if (empty($setting['payment_wx_token'])) {
                $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
                for ($i = 0; $i < 8; $i++) {
                    $setting['payment_wx_token'] .= $chars[mt_rand(0, strlen($chars) - 1)];
                }
            }
            $setting['payment_wx_url'] = SITE_URL . '/index.php?app=weixin';
            $this->assign('setting', $setting);
            $this->display('my_wxconfig.index.html');
        } else {
            $data['payment_wx_appid'] = trim($_POST['payment_wx_appid']);
            $data['payment_wx_secret'] = trim($_POST['payment_wx_secret']);
            $data['payment_wx_token'] = trim($_POST['payment_wx_token']);
            $model_setting->setAll($data);
            $this->show_message('edit_wxconfig_successed');
        }
    }
}

?>